<template>
	<view>
		<view class="container flex-s-b">
			<view class="left">
				<u-button @click="rejectMaskShow=true">驳回</u-button>
			</view>
			<view class="right">
				<u-button type="warning" @click="passingMaskShow=true">通过</u-button>
			</view>
		</view>
		<u-popup :show="rejectMaskShow" @close="rejectMaskShow=false" mode='center'>
			<view class="popup">
				<view class="u-m-b-30">*驳回原因</view>
				<u--textarea class="u-m-b-30" v-model="reject_reason" placeholder="请输入内容"></u--textarea>
				<u-button type="error" @click="rejecfun">确认驳回</u-button>
			</view>
		</u-popup>
		<u-popup :show="passingMaskShow" @close="passingMaskShow=false" mode='center'>
			<view class="popup">
				<view class="u-m-b-30">通过原因</view>
				<u--textarea class="u-m-b-30" v-model="passingText" placeholder="请输入内容"></u--textarea>
				<u-button type="error" @click="passingun">确认通过</u-button>
			</view>
		</u-popup>
	</view>
</template>

<script setup>
	import {
		ref
	} from "vue"
	import {
		debounce
	} from "lodash"
	const INTERFACE = uni.$store('Interface')
	const rejectMaskShow = ref(false)
	const passingMaskShow = ref(false)
	const reject_reason = ref('')
	const passingText = ref('')
	const props = defineProps({
		id: String
	})
	const back = () => {
		uni.navigateBack({
			delta: 1,
			success: () => {
				INTERFACE.examinePageForm.page = 1
				INTERFACE.getexaminePageList()
			}
		})
	}
	const fun1 = () => {
		if (!reject_reason.value) {
			uni.showToast({
				title: '请填写驳回原因',
				icon: 'none'
			})
			return
		}
		uni.$u.http.post('/flow/v1.0/audit_reject', {
			flow_apply_id: props.id,
			reject_reason: reject_reason.value,
		}).then(res => {
			rejectMaskShow.value = false
			back()

		})
	}
	const fun2 = () => {
		uni.$u.http.post('/flow/v1.0/audit_pass', {
			flow_apply_id: props.id,
			reject_reason: passingText.value,
		}).then(res => {
			passingMaskShow.value = false
			back()

		})
	}
	
	const rejecfun = debounce(fun1, 500, {
		'leading': false,
	})
	const passingun = debounce(fun2, 500, {
		'leading': false,
	})
</script>

<style lang="scss" scoped>
	.container {
		width: 90%;
		margin: 30rpx auto;
	}

	.left {
		width: 30%;
	}

	.right {
		width: 30%;
	}

	.popup {
		padding: 30rpx;
		width: 600rpx;
	}
</style>